package com.changli05._map;

import org.junit.Test;

import java.util.*;

/*
- 增
  put (Obeject value)

  putAll (Map map)

- 删

  remove (Object key)

- 改

- put (Obeject value)
  putAll (Map map)

- 查

  Object get (Object key)

- 长度

  size()

- 遍历

  1. 遍历key集 Set keySet()
  2. 遍历value集Collection values ()
  3. 遍历entry集Set entrySet()
* */
public class MapTest {
    @Test
    public void test() {
        Map m = new HashMap();
        //增
        m.put("name","zky");
        m.put("age",23);
        System.out.println(m);
        //删
        m.remove("age");
        System.out.println(m);
        //改
        m.put("name","lyf");
        System.out.println(m);
        //查
        System.out.println(m.get("name"));
        //长度
        System.out.println(m.size());




        m.put("age",23);
        m.put("id",1001);
        m.put("grade",2);
        m.put("marks",100);




        //遍历
        Set s = m.keySet();
        Iterator it = s.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        Collection c = m.values();
        System.out.println(c);
//        Iterator it1 = c.iterator();
//        while (it.hasNext()){
//            System.out.println(it.next());
//        }
        for (Object o : c) {
            System.out.println(o);
        }
        Set s1 = m.entrySet();
        Iterator it2 = s1.iterator();
        while (it2.hasNext()){
            Map.Entry entry = (Map.Entry)it2.next();
            System.out.println(entry.getKey()+"->"+entry.getValue());
        }
    }
}
